// pages/shops/index.js
Page({
  data: {
    isToday: '',
    start: '',
    end: '',
    disabled: 'disabled'
  },
  onLoad: function (options) {
    var id = options.id
    this.setData({seller_id: id})
  },
  onReady: function () {
    var date = new Date(),
        y = date.getFullYear(),
        m = date.getMonth() + 1,
        m = (m >= 10) ? m : '0' + m,
        d = date.getDate(),
        d = (d >= 10) ? d : '0' + d,
        today = y + '-' + m + '-' + d,
        _this = this,
        today_date = m + '月' + d + '日';
    _this.setData({today: today, date: today_date});
  },
  onShow: function () {
  
  },
  onHide: function () {
  
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
  
  },
  selectStart(e) {
    var _this = this,
        val = e.detail.value,
        end = _this.data.end,        //获取目的地的值
        data = {}

        if(val != '' && end != '') data['disabled'] = ''
          else data['disabled'] = 'disabled'  

        data['start'] = val
        _this.setData(data);
  },
  selectEnd(e) {
    var _this = this,
        val = e.detail.value,
        start = _this.data.start,    //获取出发地点的值
        data = {}

    if (val != '' && start != '') data['disabled'] = ''
    else data['disabled'] = 'disabled'

    data['end'] = val
    _this.setData(data);
  },
  selectDate(e) {
    var _this = this,
        val = e.detail.value,
        date = val.split('-'),
        today = _this.data.today,
        data = {}
    data['date'] = date[1] + '月' + date[2] + '日';

    if(val != today) {
      data['isToday'] = 'is-today';
    }else {
      data['isToday'] = '';
    }
    _this.setData(data);
  },
  exchange() {
    var _this = this,
        start = _this.data.start,
        end = _this.data.end
    _this.setData({
      start: end,
      end: start
    })
  },
  checkboxChange(e) {
    var _this = this,
        val = e.detail.value,
        data = {}
    
    for(var j in val) {
      for (var i = 0; i < _this.data.items.length; i++) {
        if (val[j] == _this.data.items[i].val) {
          data['items[' + i + '].checked'] = 'checked';
          data['items[' + i + '].icon'] = 'success_checked';
        } else {
          data['items[' + i + '].checked'] = '';
          data['items[' + i + '].icon'] = 'success';
        }
      }
    }

    _this.setData(data)
  },
  submit(e) {
    var id = this.data.seller_id,
      value = e.detail.value  
    wx.navigateTo({
      url: '/pages/shops/search?id='+id+'&flt_start='+value.flt_start+'&flt_end='+value.flt_end+'&flt_date='+value.flt_date
    })
  }
})